/*
 *Copyright © 2015 zhaorongbao
 *招融宝
 *http://zhaorongbao.com
 *All rights reserved.
 */
package com.hanhai.zrb.backend.web.freemaker;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.servlet.view.freemarker.FreeMarkerView;

import com.hanhai.common.consts.GlobalConst;
import com.hanhai.common.util.BasePropertyConfigurer;
import com.hanhai.zrb.backend.admin.model.BackendUser;
import com.hanhai.zrb.backend.util.BackendLoginUtil;

public class BackendFreemarkerView extends FreeMarkerView {

	@Override
	protected void exposeHelpers(Map<String, Object> model,
			HttpServletRequest request) throws Exception {

		String contextPath = request.getContextPath();
		String isLocal=BasePropertyConfigurer.getContextProperty(GlobalConst.IS_LOCAL);
		if(isLocal != null && isLocal.equals("y")){
			model.put("base", contextPath);
		}else{
			String backendDomain=BasePropertyConfigurer.getContextProperty(GlobalConst.BACKEND_DOMAIN);
			if(StringUtils.isEmpty(backendDomain)){
				throw new RuntimeException("系统配置错误");
			}
			model.put("base", backendDomain);
		}
		String backendStaticUrl=BasePropertyConfigurer.getContextProperty(GlobalConst.BACKEND_STATIC_URL);
		if(StringUtils.isEmpty(backendStaticUrl)){
			throw new RuntimeException("backendStaticUrl is null");
		}
		model.put("static", backendStaticUrl);
		
		BackendUser backendUser = BackendLoginUtil.getCurrentUser();

		model.put("currentUser", backendUser);
		//变量，可以直接在模版中访问
		model.putAll(BasePropertyConfigurer.getCtxPropertiesMap());
		super.exposeHelpers(model, request);
	}

}
